import 'package:dio/dio.dart';
import 'package:getx_learn/app/modules/weichat_post/modules/post/constant/config.dart';

class WxHttpUtil {
  static final WxHttpUtil _instance = WxHttpUtil._internal();

  factory WxHttpUtil() => _instance;

  Dio? _dio;

  WxHttpUtil._internal() {
    if (_dio == null) {
      _dio = Dio();
      _dio?.options = BaseOptions(
        baseUrl: apiBaseUrl,
        connectTimeout: Duration(milliseconds: 10000),
        // 10s
        receiveTimeout: Duration(milliseconds: 5000),
        headers: {},
        contentType: "application/json; charset=utf-8",
        responseType: ResponseType.json,
      );
    }
  }

  /// get 请求
  Future<Response> get(String url, {Map<String, double>? data}) async {
    Response response = await _dio!.get(url, queryParameters: data);
    return response;
  }

  /// post 请求
  Future<Response> post(String url, {Map<String, dynamic>? data}) async {
    Response response = await _dio!.post(url, data: data);
    return response;
  }


}
